class AcademicTerm < ActiveRecord::Base
  belongs_to :term
  
  has_many :groups
  has_many :student_plan_enrollments


  validates_presence_of :name, :abbreviation, :code, :term_id, :starts, :ends
  validates_uniqueness_of :code
  validate :start_end_dates

  protected
  def start_end_dates
    errors.add(:ends, 'La fecha de término del periodo debe de ser después de la de inicio') if ends.nil? ||
      ends <= starts
  end

end
